/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package binh;

import binh.data.CEmuDataBase;
import caro.CCaroLogic;
import we.dispatcher.CCoreServer;

/**
 *
 * @author ADMIN
 */
public class CMain
{

    
    protected static CGameLogic CreateLogic(int AppId, CTable Table)
    {
        //CDebug.Trace(this, "AppID create : " + AppId);
        switch (AppId)
        {
            default:
                return new CCaroLogic(Table);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {   
        CGlobal.ClientList = new CClientMgr(CConfig.MaxClient);
        CGlobal.AppContainer = new CAppMgr();
        
        CGlobal.Database = new CEmuDataBase();
    

        int[] AppID =
        {
            1, 2, 3, 5, 7, 8, 9
        };

        for (int I = 0; I < AppID.length; I++)
        {
            CApp GameNet = new CApp(CGlobal.AppContainer, AppID[I]);
            CGlobal.AppContainer.AddGameNet(GameNet);

            for (int J = 0; J < CConfig.MAX_CHANNEL_IN_GAME; J++)
            {
                CChannel Channel = new CChannel(J, GameNet);
                GameNet.AddChannel(Channel);
                if (J < 3)
                {
                    Channel.ChannelType = 0;
                } else if (J < 6)
                {
                    Channel.ChannelType = 1;
                } else
                {
                    Channel.ChannelType = 2;
                }

                for (int K = 0; K < CConfig.MAX_TABLE_IN_CHANNEL; K++)
                {
                    CTable Table = new CTable(K, Channel);
                    Channel.AddTable(Table);
                    Table.SetGameLogic(CreateLogic(Table.GetAppID(), Table));
                    CLoopers.Instance().AddLooper(Table);
                }
            }
        }
                
        CGlobal.Handler = CBinhHandler.Instance();
        CCoreServer.instance().SetHandler(CBinhHandler.Instance());
        CCoreServer.instance().StartServer();
    }
}
